home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / comm / 110a115a.zip / WINHOST.ZIP / WHUTILS.SLT < prev    next >
Text File  |  1995-12-22  |  3KB  |  135 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Do NOT compile this file.  It is included (#INCLUDE) in the WINHOST.SLT
  4. //  and WCONFIG.SLT files.  If you change it, simply save the changes and
  5. //  recompile those files.  They will compile this file as necessary.
  6. //
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. //  Functions common to the main HOST script and the script that maintains
  10. //  the configuration file
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13.  
  14. // Get the directory in which we are going to store our stuff
  15.  
  16. get_our_dir () {
  17.     int length;
  18.   getRunPath(our_dir);
  19.   if (!our_dir)
  20. //      if (!getenv ("HOST2DIR", our_dir)) // environment variable there?
  21.       our_dir = _script_dir;
  22.  
  23.   // add a backslash on the end if necessary
  24.   strupper (our_dir);
  25.   length = strlen (our_dir);
  26.   if (length) --length;
  27.      if (subchr(our_dir, length) != '\')
  28.        strcat (our_dir, "\");
  29. }
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32.  
  33. read_host_config_file() {
  34.  
  35.   str s[80];
  36.   int f, ret_val;
  37.  
  38.   s = our_dir;
  39.   strcat(s, "WINHOST.CNF");
  40.  
  41.   if (!(f = fopen(s, "r"))) {
  42.     printsc("Can't open ");
  43.     prints(s);
  44.     return -1;
  45.   }
  46.  
  47.   prints ("Reading configuration file ...");
  48.   ret_val = 1;
  49.  
  50.   // Read our download directory
  51.   if (fgets (s, 80, f) != -1) {
  52.     host_downloads = s;
  53.  
  54.     // Read our upload directory
  55.     if (fgets (s, 80, f) != -1) {
  56.      host_uploads = s;
  57.  
  58.      if (fgets (s, 80, f) != -1) {
  59.       host_message = s;
  60.        
  61.       // Read direct connection flag
  62.       if (fgets (s, 80, f) != -1) {
  63.         direct_connect = (toupper(subchr(s, 0)) == 'D');
  64.  
  65.         // Read modem lock flag
  66.         if (fgets (s, 80, f) != -1) {
  67.           modem_lock = stoi(s);
  68.  
  69.           // Read closed-system flag
  70.           if (fgets (s, 80, f) != -1) {
  71.             closed_sys = (toupper (subchr (s, 0)) == 'C');
  72.           }
  73.  
  74.           // Error condition handling
  75.           else {
  76.             prints ("Error reading closed-system line!");
  77.             ret_val = -1;
  78.           }
  79.         }
  80.         else {
  81.           prints ("Error reading modem line!");
  82.           ret_val = -1;
  83.         }
  84.       }
  85.       else {
  86.         prints ("Error reading direct connect line!");
  87.         ret_val = -1;
  88.       }
  89.      }
  90.      else {
  91.        prints ("Error reading host message directory line!");
  92.        ret_val = -1;
  93.      }
  94.     }
  95.     else {
  96.       prints ("Error reading host upload directory line!");
  97.       ret_val = -1;
  98.     }
  99.   }
  100.   else {
  101.     prints ("Error reading host download directory line!");
  102.     ret_val = -1;
  103.   }
  104.  
  105.   fclose(f);
  106.   return (ret_val);
  107. }
  108.  
  109. //////////////////////////////////////////////////////////////////////////////
  110.  
  111. check_directory (str dirname) {
  112.  
  113.   str s[80];
  114.   int i, a;
  115.  
  116.   // first remove trailing slashes
  117.  
  118.   s = dirname;
  119.   i = strlen(s);
  120.   if (i > 0)
  121.     if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  122.       setchr(s, i - 1, 0);
  123.   if (s && !(strlen(s) == 2 && subchr(s, 1) == ':')) {
  124.     a = fileattr(s);
  125.     if (a == -1 || !(a & 16)) {
  126.       printsc (s);
  127.       prints (" does not exist.^M^J");
  128.       return 0;                  // not a directory or doesn't exist
  129.     }
  130.   }
  131.  
  132.   return 1;
  133.  
  134. }
  135.